/*基类*/
Ext.define('MyDesktop.RemoteListCombo', {
	extend : 'Ext.form.ComboBox',
	remoteUrl : '/',
	queryMode: 'remote',
	fieldLabel: '/',
	valueField: 'id',
	fields : ["id","name","code"],
    tpl: Ext.create('Ext.XTemplate',
        '<tpl for=".">',
            '<div class="x-boundlist-item">{code}  -  {name}</div>',
        '</tpl>'
    ),
    displayTpl: Ext.create('Ext.XTemplate',
        '<tpl for=".">',
            '{code} - {name}',
        '</tpl>'
    ),
	 initComponent : function( config ){
		 Ext.apply(this, config);
	 	 var me = this;
	      me. store = Ext.create('Ext.data.Store', {
	    	     autoLoad: true,
	    	     fields: me.fields,
	    	     proxy: {
	    	         type: 'ajax',
	    	         url:  me.remoteUrl,
	    	         reader: {
	 		            type: 'json',
	 	            	root : 'result',	
	 	                totalProperty : 'totalRecords'	
	 		        }
	    	     }
	    	 });
	      this.callParent(arguments);
	 }
});

/*店铺*/
Ext.define('MyDesktop.ShopListCombo',{
	extend : 'MyDesktop.RemoteListCombo',
	alias: 'widget.shopListcombo',
	remoteUrl:BP+'shop/pageQueryTShops',
	fieldLabel:'店铺',
	pageSize:6,
	width : 230,
	editable: false,
	valueField:'shopCode',
	fields : ["id","shopName","shopCode"],
    tpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<div class="x-boundlist-item">{shopCode} - {shopName}</div>',
            '</tpl>'
        ),
        displayTpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '{shopCode} - {shopName}',
            '</tpl>'
        ),
	 initComponent : function( config ){
		 this.callParent(arguments);
	 }
});

/*经销商列表*/
Ext.define('MyDesktop.DistListCombo',{
	extend : 'MyDesktop.RemoteListCombo',
	alias: 'widget.distListcombo',
	remoteUrl:BP+'dist/pageQueryTdist',
	fieldLabel:'经销商',
	width : 230,
	pageSize:6,
	fields : ["id","distributorName","distributorCode","shop_Code","shop_Name"],
	valueField:'distributorCode',	//
    tpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<div class="x-boundlist-item">{distributorCode} - {distributorName}</div>',
            '</tpl>'
        ),
        displayTpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '{distributorCode} - {distributorName}',
            '</tpl>'
        ),
	 initComponent : function( config ){
		 this.callParent(arguments);
	 }
});

/*产品列表*/
Ext.define('MyDesktop.ProdListCombo',{
	extend : 'MyDesktop.RemoteListCombo',
	alias: 'widget.prodListcombo',
	remoteUrl:BP+'prod/pageQueryTprod',
	pageSize:6,
	fieldLabel:'产品',
	width : 230,
	fields : ["id","productCode","productName","productPv","productBv","productPrice"],
	valueField:'productCode',
    tpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<div class="x-boundlist-item">{productCode} - {productName}</div>',
            '</tpl>'
        ),
        displayTpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '{productCode} - {productName}',
            '</tpl>'
        ),
	 initComponent : function( config ){
		 this.callParent(arguments);
	 }
});

/*职级*/
var s1 = Ext.create('Ext.data.Store', {
    fields: ['id', 'name'],
    data : [
        {"id":102001, "name":"一星"},
        {"id":102002, "name":"二星"},
        {"id":102003, "name":"三星"},
        {"id":102004, "name":"四星"},
        {"id":102005, "name":"五星"},
        {"id":102006, "name":"六星"},
        {"id":102007, "name":"七星"},
        {"id":102008, "name":"八星"},
        {"id":102009, "name":"九星"}
    ]
});

Ext.define('MyDesktop.RankCombo',{
	extend : 'Ext.form.ComboBox',
	alias : 'widget.rankCombo',
    fieldLabel: '职级',
    store: s1,
    queryMode: 'local',
    valueField: 'id',
    displayField :'name'
});

/*是否有效*/
var s2 = Ext.create('Ext.data.Store', {
    fields: ['id', 'name'],
    data : [
        {"id":'1', "name":"--有效--"},
        {"id":'0', "name":"--无效--"}
    ]
});

Ext.define('MyDesktop.ValidCombo',{
	extend : 'Ext.form.ComboBox',
	alias : 'widget.validCombo',
    fieldLabel: '产品状态',
    store: s2,
    queryMode: 'local',
    valueField: 'id',
    displayField :'name'
});


/*颜色*/
function ColorRender(value, p, record){
	return  "<b><font color=red>"+value+"</font></b>";
}

/*币值*/
function MoneyRender(value, p, record){
	return  "<b><font color=red>"+value+"</font></b>";
}

/*比例*/
function PerctRender(value, p, record){
	if(value == 0 || typeof(value) =="string"){
		return  value+" %";
	}else{
		return  "<b><font color=red>"+value+" %"+"</font></b>";
	}
}

/*日期*/
function DateRender(value, p, record) {   
    if (Ext.isEmpty(value)) {  
        return '';   
    } else {   
        if (Ext.isDate(value))   
            return Ext.util.Format.date(value, 'Y-m-d'); 
        else   
            return Ext.util.Format.date(new Date(value), 'Y-m-d');   
    }   
}
